/**
 * 
 */
package com.school.dao;

/**
 * @author KK
 *
 */
import java.sql.Connection;
import java.sql.DriverManager;
//import java.sql.ResultSet;
import java.sql.SQLException;

public class ConnectionUtil {
	
	private static final String driverClass ="com.mysql.jdbc.Driver";
	private static final String url ="jdbc:mysql://localhost:3306/school";
	private static final String username ="root";
	private static final String password ="mysql";			//mysql/root	
	
	
/*
	private static final String driverClass ="com.ibm.db2.jcc.DB2Driver";
	private static final String url ="jdbc:db2://localhost:50000/EGAS";
	private static final String username ="db2admin";
	private static final String password ="db2admin";
*/
	
	static
	{
		try
		{
			
			Class.forName(driverClass);
			System.out.println("class load successfully");
		}
		catch(ClassNotFoundException ex)
		{
			System.out.println("Class loaded error");
			ex.printStackTrace();
		}
	}
	public static Connection getConnection() throws SQLException
	{
		try{
			System.out.println("get conn successfully");
			return DriverManager.getConnection(url,username,password);
		}
		catch (Exception e) {
			e.printStackTrace();
			System.out.println("get connection error");
			return null;
		}
		
	}
	public static void CloseDbResources(Connection con)
	{
		try
		{
			if(con!=null)
			{
				con.close();
				con=null;
			}
		}
		catch(SQLException ex)
		{
			ex.printStackTrace();
		}
	}
}
